//
//  ZCRecommendCell.m
//  百思不得姐
//
//  Created by Ning Xie on 16/8/25.
//  Copyright © 2016年 zhangchong. All rights reserved.
//

#import "ZCRecommendCell.h"
#import "ZCRecommendModel.h"

@interface ZCRecommendCell ()

@property(strong, nonatomic) UIImageView *headerImage;
@property(strong, nonatomic) UILabel *nameLabel;
@property(strong, nonatomic) UILabel *subNumLabel;
@property(strong, nonatomic) UIButton *subButton;

//@property (nonatomic, strong) UIView *lineView;

@end


@implementation ZCRecommendCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]){
        
        [self setupUI];
        self.selectionStyle = UITableViewCellSelectionStyleNone;
//        self.lineView = [[UIView alloc]init];
//        self.lineView.backgroundColor = ZCGlobalRBG;
//        [self.contentView addSubview:_lineView];
//        [_lineView mas_makeConstraints:^(MASConstraintMaker *make) {
//            make.bottom.trailing.leading.mas_equalTo(self.contentView);
//            make.height.mas_equalTo(1);
//        }];
    };
    
    return self;
}

-(void)setupUI{
    
    self.headerImage = [[UIImageView alloc]init];
    self.nameLabel = [[UILabel alloc]init];
    self.subNumLabel = [[UILabel alloc]init];
    self.subButton = [UIButton buttonWithType:UIButtonTypeCustom];
    
    _nameLabel.font = [UIFont systemFontOfSize:15];
    [_nameLabel sizeToFit];
    _nameLabel.textAlignment = NSTextAlignmentLeft;
    
    _subNumLabel.font = [UIFont systemFontOfSize:14];
    [_subNumLabel sizeToFit];
    _subNumLabel.textAlignment = NSTextAlignmentLeft;
    _subNumLabel.textColor = [UIColor grayColor];
    
    _subButton.titleLabel.font = [UIFont systemFontOfSize:14];
    [_subButton setTitle:@"+ 订阅" forState:UIControlStateNormal];
//    [_subButton setTitle:@"取消关注" forState:UIControlStateSelected];
    [_subButton setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
//    [_subButton setTitleColor:[UIColor blackColor] forState:UIControlStateSelected];
    [_subButton setBackgroundImage:[UIImage imageNamed:@"FollowBtnBg"] forState:UIControlStateNormal];
    [_subButton addTarget:self action:@selector(subButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    _subButton.adjustsImageWhenHighlighted = NO;
    
    [self.contentView addSubview:_headerImage];
    [self.contentView addSubview:_nameLabel];
    [self.contentView addSubview:_subNumLabel];
    [self.contentView addSubview:_subButton];
    
    [_headerImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.contentView);
        make.leading.equalTo(self.contentView).offset(10);
        make.width.height.equalTo(self.contentView.mas_height).offset(-20);
    }];
    
    [_nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_headerImage);
        make.leading.equalTo(_headerImage.mas_trailing).offset(10);
    }];
    
    [_subNumLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(_headerImage);
        make.leading.equalTo(_headerImage.mas_trailing).offset(10);
    }];
    
    [_subButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.contentView);
        make.trailing.equalTo(self.contentView).offset(-10);
        make.width.mas_equalTo(70);
        make.height.mas_equalTo(30);
    }];

    
    
}
-(void)subButtonAction:(UIButton*)sender{
    ZCLog(@"订阅按钮被点击了");
}

-(void)setModel:(ZCRecommendModel *)model{
    _model = model;
    
    
    [self.headerImage sd_setImageWithURL:[NSURL URLWithString:model.image_list] placeholderImage:[UIImage imageNamed:@"defaultUserIcon"]];
    self.subNumLabel.text = [NSString stringWithFormat:@"%@订阅",model.sub_number];
    self.nameLabel.text = model.theme_name;
    
    
}

-(void)setFrame:(CGRect)frame{
    
    frame.size.height -= 1;
    frame.origin.x = 10;
    frame.size.width -= 2*frame.origin.x;
    
    [super setFrame:frame];
}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
